using UnityEngine;

public class FlyCam : MonoBehaviour
{
	private int currentWaypoint;

	public float rotateSpeed = 1f;

	public float moveSpeed = 10f;

	public float magnitudeMax = 10f;

	private void Update()
	{
		if (WaypointCam.waypoints.Length <= 0)
		{
			return;
		}
		Transform transform = base.transform;
		Vector3 position = WaypointCam.waypoints[currentWaypoint].position;
		float x = position.x;
		Vector3 position2 = WaypointCam.waypoints[currentWaypoint].position;
		float y = position2.y;
		Vector3 position3 = WaypointCam.waypoints[currentWaypoint].position;
		Vector3 vector = transform.InverseTransformPoint(new Vector3(x, y, position3.z));
		Vector3 position4 = WaypointCam.waypoints[currentWaypoint].position;
		float x2 = position4.x;
		Vector3 position5 = WaypointCam.waypoints[currentWaypoint].position;
		float y2 = position5.y;
		Vector3 position6 = WaypointCam.waypoints[currentWaypoint].position;
		Vector3 a = new Vector3(x2, y2, position6.z);
		Quaternion to = Quaternion.LookRotation(a - base.transform.position);
		base.transform.rotation = Quaternion.Slerp(base.transform.rotation, to, Time.deltaTime * rotateSpeed);
		Vector3 a2 = base.transform.TransformDirection(Vector3.forward);
		base.transform.position += a2 * moveSpeed * Time.deltaTime;
		if (vector.magnitude < magnitudeMax)
		{
			currentWaypoint++;
			if (currentWaypoint >= WaypointCam.waypoints.Length)
			{
				currentWaypoint = 0;
			}
		}
	}
}
